import axios from "axios"
axios.jar = true
axios.withCredentials = true
export let getUrl = (url) => {
    let r = url;
    if (!r) {
        return;
    }
    let u = function (n, t) {
        var r = new RegExp(
            "[?&]{1}" + t + "=([^&]+)([\\/\\\\][^?#]*)?([?#].*)?",
            "i"
        ),
            i = n.match(r);
        return i ? i[1] : null;
    };
    if (
        !r ||
        (r.indexOf(".bing.com/ck") < 0 &&
            r.indexOf(".bing.com/ac") < 0 &&
            r.indexOf(".bing.com/clk") < 0)
    ) {
        return;
    }
    let t = u(r, "u");
    if (!t) {
        return;
    }
    t && t.startsWith("a1") && (t = t.substring(2));

    t = t.replace(/_/g, "/");
    t = t.replace(/-/g, "+");
    t = decodeURIComponent(atob(t));
    u = null;
    return t;
};

export const getResultByKeyword = async (url,params) => {
    // console.log('fffffffffffff',url,params);

    let bing = url|| `https://cn.bing.com/search?q=${params}&qs=n&FORM=BESBTB&sp=-1&lq=0&pq=oled&sc=13-4&ghsh=0&ghacc=0&setlang=en&ensearch=1&cc=us`;
    try {
        let res = await axios.get(bing, {
            headers: {
                "User-Agent":
                    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36",
                // cookie:
                //     "_EDGE_V=1; SRCHD=AF=NOFORM; SRCHUID=V=2&GUID=59D5F1B8109E4D1DB1B29619D3DACCE1&dmnchg=1; _EDGE_CD=u=en-us; _FP=hta=on; _UR=QS=0&TQS=0; MicrosoftApplicationsTelemetryDeviceId=8e78e2d0-d2f8-4a87-941b-aa9fd70c8ab2; MUID=23CC27AF7DD263CA161C356F7C976295; MUIDB=23CC27AF7DD263CA161C356F7C976295; MSPTC=f33k70hbkmPBUgUHxxnt-9BmKzADmAtLK20rdGUe6wA; SRCHS=PC=U531; _SS=SID=01B163E9AA4A634633B27732AB2C6261&R=200&RB=0&GB=0&RG=200&RP=200&PC=U531; _HPVN=CS=eyJQbiI6eyJDbiI6MSwiU3QiOjAsIlFzIjowLCJQcm9kIjoiUCJ9LCJTYyI6eyJDbiI6MSwiU3QiOjAsIlFzIjowLCJQcm9kIjoiSCJ9LCJReiI6eyJDbiI6MSwiU3QiOjAsIlFzIjowLCJQcm9kIjoiVCJ9LCJBcCI6dHJ1ZSwiTXV0ZSI6dHJ1ZSwiTGFkIjoiMjAyNC0wOC0xNFQwMDowMDowMCIsIklvdGQiOjAsIkd3YiI6MCwiVG5zIjowLCJEZnQiOm51bGwsIk12cyI6MCwiRmx0IjowLCJJbXAiOjQsIlRvYm4iOjB9; ENSEARCH=BENVER=1; _EDGE_S=ui=en-us&F=1&SID=01B163E9AA4A634633B27732AB2C6261; BFPRResults=FirstPageUrls=7561CFEE8F3B4AE12F516A8A0152EE40%2CB59AEF53F05D992A70AADB91B453EEB4%2C578DE1DE80933A8DBBC316AA5E7B79FE%2CD197ACD076FFA6F277715128A16CCF20%2C4B3D2E6484EDAE8144D671DF9567A8BA%2C71B3BE44C588E9DFB1593B979FBA0604%2C1AA3BF83D2C0EAC4CC80A254FD183844%2C4E5F2E6E69C6B136202DB56E2DC44818%2CAA5FEB4E348831F7F4E950BCC5A41D6A%2CA8BE2757C5BDAF98E70794EA89799CC6&FPIG=501DAD6311424540B7EF5918754C33EB; _TTSS_IN=isADRU=0&hist=WyJ6aC1IYW5zIiwiYXV0by1kZXRlY3QiXQ==; _tarLang=default=en; _TTSS_OUT=hist=WyJ6aC1IYW5zIiwiYWYiLCJlbiJd; ULC=P=14068|1:1&H=14068|1:1&T=14068|1:1; _Rwho=u=d&ts=2024-08-21; SNRHOP=I=&TS=; SRCHUSR=DOB=20240814&T=1724398007000; ABDEF=V=13&ABDV=13&MRB=0&MRNB=1724398017613; USRLOC=HS=1&ELOC=LAT=22.65792465209961|LON=114.06501770019531|N=Longgang%2C%20Guangdong|ELT=4|&BID=MjQwODIyMjIyNzAyXzI3NDM0N2I3ZmE3NjA0YzAwNWIxMzdiZjM3ZWU0YTUwMDNiMGNhNzUyMTY4N2E3YzgyZmNkNjMwMDkxYjc2ZDM=; ipv6=hit=1724404366284; SRCHHPGUSR=SRCHLANG=en&PV=10.0.0&BZA=0&HV=1724400777&DM=0&BRW=NOTP&BRH=M&CW=772&CH=748&SCW=1164&SCH=2362&DPR=1.3&UTC=480&EXLTT=31&WTS=63859994808&PRVCW=772&PRVCH=748&IG=FF324625491E456695B1ED984726C6AA; _C_ETH=1; GC=HouggUm6h4K1P9iYhAk6tIy-Ox-8W50wAJwy3dV8jK8T6R6_J1EktQUv8mLhNNwhB-rVOITfLk4UQra6Aonj5w; _RwBf=r=0&ilt=200&ihpd=0&ispd=6&rc=200&rb=0&gb=0&rg=200&pc=200&mtu=0&rbb=0&g=0&cid=&clo=0&v=6&l=2024-08-23T07:00:00.0000000Z&lft=2024-08-13T00:00:00.0000000-07:00&aof=0&ard=0001-01-01T00:00:00.0000000&rwdbt=0001-01-01T00:00:00.0000000&rwflt=0001-01-01T00:00:00.0000000&o=2&p=&c=&t=0&s=0001-01-01T00:00:00.0000000+00:00&ts=2024-08-23T08:12:59.1779775+00:00&rwred=0&wls=&wlb=&wle=&ccp=&cpt=&lka=0&lkt=0&aad=0&TH=",
            },
        });
        // console.log(res,'fffffffffff');
        return res;
    } catch (error) {
        return null
    }
}
